﻿function getPost() {
  new Ajax.Request(
    "../scripts/proxyBlog.cgi",
    { method: "get",
     parameters: { method: 'getPost',
                   id: 'da4c9ca3-4a71-436f-b85d-210207059857',
                   type: 'json' },
     onSuccess:
       function(transport) {
         var res = eval('(' + transport.responseText + ')');
         $("title").update(res['title']);
         $("blog").update(res['content']);
       }
    }
  );
}

var entryToSave;
 
window.onload = function() {
  getPost();
 
  new Ajax.InPlaceEditor(
      'blog',
      '../scripts/proxyBlog.cgi',
      {
         formId: 'whatever',
         okText: 'OK!',
         cancelText: 'Cancel',
         savingText: 'Saving...',
         rows: 30,
         cols: 40,
         callback: function(form, value) {
           entryToSave = value;  // save the value for later
           return 'method=editPost&id=da4c9ca3-4a71-436f-b85d-210207059857&content=' + escape(value);
         },
         onComplete: function() {
           $("blog").update(entryToSave);
         }
      }
  );
}
